package com.whq.thrift.api.web.admin.db.verify;

import java.util.Map;

import org.apache.ibatis.jdbc.SqlBuilder;

import com.whq.common.StringUtil;

public class MerchantKeySqlProvider {
	public String getSelectRecordsSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_merchant_key");
		if ((parameter.get("merchantName")) != null && (StringUtil.isNotBlank(parameter.get("merchantName").toString()))) {
			SqlBuilder.WHERE("merchant_name like #{merchantName}");
		}
		SqlBuilder.ORDER_BY("merchant_name asc");
		return SqlBuilder.SQL() + " limit #{beginIndex}, #{maxCount} ";
	}
	
	public String getSelectCountSql(Map<String, Object> parameter){
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("count(*)");
		SqlBuilder.FROM("t_merchant_key");
		if ((parameter.get("merchantName")) != null && (StringUtil.isNotBlank(parameter.get("merchantName").toString()))) {
			SqlBuilder.WHERE("merchant_name like #{merchantName}");
		}
		return SqlBuilder.SQL();
	}
	
	
	public String getUpdateSql(MerchantKey merchantKey){
		SqlBuilder.BEGIN();
		SqlBuilder.UPDATE("t_merchant_key");
		if(StringUtil.isNotBlank(merchantKey.getPublicKey())){
			SqlBuilder.SET("public_key=#{publicKey}");
		}
		if(StringUtil.isNotBlank(merchantKey.getSignatureKey())){
			SqlBuilder.SET("signature_key=#{signatureKey}");
		}
		SqlBuilder.WHERE("merchant_name=#{merchantName}");
		return SqlBuilder.SQL();
	}

}
